class Admin::OrdersController < Admin
  
  def index
    @status = params[:id]
    if @status.blank?
      @status = 'all'
    end
    conditions = @status
    @page_title = "Listing #{@status} orders"
    @orders = Order.full_list(params[:page], conditions)
  end

  def show
    @page_title = "Displaying order ##{params[:id]}"
    @order = Order.find(params[:id])
  end
  
  def close
    order = Order.find(params[:id])
    order.update_attributes(params[:order])
    order.status = "closed"
    order.save
    flash[:notice] = "Order #{order.id} has marked as 'closed' by #{order.last_edited_by}"
    redirect_to :action => 'index', :id => 'closed'
  end
  
  def shipped
    order = Order.find(params[:id])
    order.update_attributes(params[:order])
    order.status = "shipped"
    order.save
    flash[:notice] = "Order #{order.id} has been marked as 'shipped' by #{order.last_edited_by}"
    redirect_to :action => 'index', :id => 'shipped'
  end
  
  def new_comment
    comment = OrderComments.new(params[:order_comment])
    comment.save!
    @order = Order.find(params[:id])
    @order.order_commentss << comment
    @order.save!
    flash[:notice] = "#{comment.created_by}, your comment has been saved!"
    redirect_to :action => 'show'
  end

end